import { request, type ApiResponse } from './request'

// 学生基本信息接口
export interface StudentInfo {
    id: number | string, // 大整数可能以字符串形式返回，避免精度丢失
    name: string,
    studentNum: string,
    className: string,
    phone: string,
    counselor: string,
    problemMsg: string,
    nameCheckStatus: number,
    studentNumCheckStatus: number,
    classCheckStatus: number,
    phoneCheckStatus: number
}


// 创建学生信息请求
export interface CreateStudentRequest {
  "id": number,
  "userId": number,
  "name": string,
  "studentNum": string,
  "grade": string,
  "className": string,
  "phone": string,
  "problemMsg": string,
  "email": string,
  "gpa": number,
  "indiscipline": number,
  "nameCheckStatus": number,
  "studentNumCheckStatus": number,
  "classCheckStatus": number,
  "phoneCheckStatus": number,
  "status": number,
  "createTime": string,
  "updateTime": string,
  "createBy": number,
  "updateBy": number
}



/**
 * 根据ID获取学生详情
 * @param id 学生ID
 * @returns Promise<ApiResponse<StudentInfo>>
 */
export const getStudentById = async (id: number): Promise<ApiResponse<StudentInfo>> => {
  return await request<StudentInfo>(`student/info/${id}`, {
    method: 'GET'
  })
}



/**
 * 添加学生信息
 * @param data 学生信息
 * @returns Promise<ApiResponse<StudentInfo>>
 */
export const createStudent = async (data: CreateStudentRequest): Promise<ApiResponse<StudentInfo>> => {
  return await request<StudentInfo>('student', {
    method: 'POST',
    body: data
  })
}

/**
 * 更新学生信息
 * @param data 学生信息
 * @returns Promise<ApiResponse<StudentInfo>>
 */
export const updateStudent = async (data: CreateStudentRequest): Promise<ApiResponse<StudentInfo>> => {
  return await request<StudentInfo>(`student`, {
    method: 'PUT',
    body: data
  })
}

// 获取学生列表请求参数
export interface GetStudentListRequest {
  name: string
  gender: string
  studentNum: string
  grade: string
  className: string
}

// 学生列表项接口
export interface StudentListItem {
  id?: number | string
  userId?: number
  studentId?: string
  studentNum?: string
  name?: string
  gender?: number | string
  class?: string
  className?: string
  grade?: string
  gpa?: number
  contact?: string
  phone?: string
  counselorId?: number
  avatarUrl?: string | null
  idNumber?: string | null
  hobby?: string | null
  emeContact?: string | null
  emePhone?: string | null
  address?: string | null
  problemMsg?: string
  indiscipline?: number
  nameCheckStatus?: number
  studentNumCheckStatus?: number
  classCheckStatus?: number
  phoneCheckStatus?: number
  status?: number
  classId?: number
  createTime?: string
  updateTime?: string | null
  createBy?: number
  updateBy?: number | null
  [key: string]: any
}

/**
 * 获取学生列表
 * @param data 查询参数
 * @returns Promise<ApiResponse<StudentListItem[]>>
 */
export const getStudentList = async (data: GetStudentListRequest): Promise<ApiResponse<StudentListItem[]>> => {
  return await request<StudentListItem[]>('student/list', {
    method: 'POST',
    body: data
  })
}

/**
 * 删除学生
 * @param userId 用户ID
 * @returns Promise<ApiResponse<any>>
 */
export const deleteStudent = async (userId: number | string): Promise<ApiResponse<any>> => {
  return await request<any>('student/delete', {
    method: 'DELETE',
    params: { userId: userId }
  })
}


